﻿Imports MindFusion.Diagramming
Imports MindFusion.Drawing

Public Class ClsMMShapeNode
    Inherits ShapeNode
    'represents my own shape node

#Region "Constructors"
    Public Sub New()
        MyBase.New()
        MMSetDefaultProperties()
    End Sub

    Public Sub New(ByVal parent As MindFusion.Diagramming.Diagram)
        MyBase.New(parent)
        MMSetDefaultProperties()
    End Sub

    Public Sub New(ByVal prototype As MindFusion.Diagramming.DiagramItem)
        MyBase.New(prototype)
    End Sub

    Public Sub New(ByVal prototype As MindFusion.Diagramming.DiagramNode)
        MyBase.New(prototype)
    End Sub

    Public Sub New(ByVal prototype As MindFusion.Diagramming.ShapeNode)
        MyBase.New(prototype)
    End Sub
#End Region
#Region "Properties"
#Region "Public attributes"
    Public ReadOnly Property MMRectangleForNewLink() As RectangleF
        Get
            Return SDRectangleFVirginCreator(Me.Bounds.Right - 0.3 * (Me.Bounds.Right - Me.Bounds.Left), Me.Bounds.Top, 0.3 * (Me.Bounds.Right - Me.Bounds.Left), 0.3 * (Me.Bounds.Bottom - Me.Bounds.Top))
        End Get
    End Property
#End Region
#End Region
#Region "Subs"
#Region "Overrides & Overloads Subs"
    'overrided sub for drawing handles
    Public Overrides Sub DrawHandles(ByVal graphics As MindFusion.Drawing.IGraphics, ByVal color As System.Drawing.Color)
        'Debug.Print("DrawHandles")
        Const LdbWidthOfLine As Double = 0.7

        'drawing filled polygon (triangle)
        Dim LoPoints() As PointF = { _
            New PointF(MMRectangleForNewLink.X, CType(MMRectangleForNewLink.Y + (0.5 / 2), Single)), _
            New PointF(MMRectangleForNewLink.X, MMRectangleForNewLink.Y + MMRectangleForNewLink.Height), _
            New PointF(MMRectangleForNewLink.X + CType(MMRectangleForNewLink.Width - (0.5 / 2), Single), MMRectangleForNewLink.Y + MMRectangleForNewLink.Height) _
            }
        Dim LoBrush As System.Drawing.Drawing2D.HatchBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.LightUpwardDiagonal, Drawing.Color.Black, Drawing.Color.LightCoral)
        graphics.FillPolygon(LoBrush, LoPoints)

        'drawing polygon around filled polygon (triangle)
        Dim LoPen As System.Drawing.Pen = New System.Drawing.Pen(color.Gray, 0.5)
        LoPen.DashStyle = Drawing2D.DashStyle.Solid
        graphics.DrawPolygon(LoPen, LoPoints)

        'drawing selection rectangle
        graphics.DrawRectangle(SDPenVirginCreator(color, LdbWidthOfLine), CType(Me.Bounds.X - LdbWidthOfLine / 2, Single), CType(Me.Bounds.Y - LdbWidthOfLine / 2, Single), CType(Me.Bounds.Width + LdbWidthOfLine, Single), CType(Me.Bounds.Height + LdbWidthOfLine, Single))
    End Sub
    'overrided sub called after deserialization of node. I can set some properties forcible here!
    Protected Overrides Sub OnLoad()
        MyBase.OnLoad()
    End Sub
#End Region
#Region "MM Subs"
    'default settings of shape
    Public Sub MMSetDefaultProperties()
        Me.Shape = Shapes.File
        Me.Constraints.MinHeight = 10
        Me.Constraints.MinWidth = 10
        Me.Obstacle = True ' whether this node is considered an obstacle by the link-routing algorithm
        Me.Bounds = SDRectangleVirginCreator(0, 0, 20, 20)
        Me.EnableStyledText = True 'whether styled text rendering is enabled
        Me.AnchorPattern = CreateAnchorPatternSurrounding(9) 'Represents a set of anchor points, which specify the exact locations where links are allowed to connect to nodes
        Me.CustomDraw = CustomDraw.Additional 'The custom painting code executes after item's interior and frame are painted by FlowChart.NET, but before text is rendered. In this mode, the Graphics instance passed to the custom drawing event handler has a clipping region applied to it
        Me.Font = New Font("Calibri", 10, FontStyle.Regular) 'font used to render the node's text
        Me.AllowIncomingLinks = True 'true - because of creation of notes
        Me.AllowOutgoingLinks = True 'true - because of creation of notes
        Me.Brush = New LinearGradientBrush(Color.LightYellow, Color.Khaki, 45) 'brush is used to fill the interiors of geometric shapes
        Me.Pen = New Pen("0/#FF696969/0/0/0//0/0/10/") 'pen is used to draw the outline of geometric shapes
        Me.HandlesStyle = HandlesStyle.EasyMove 'visual styles for frames that are drawn around selected nodes
        Me.ShadowOffsetX = 0.5 'horizontal offset of the shadow
        Me.ShadowOffsetY = 0.5 'vertical offset of the shadow
        'Me.ImageAlign = ImageAlign.MiddleRight 'the position and alignment of a picture relative to its destination rectangle
        Me.Text = GsStringDefaultValue 'the text displayed inside the shape node
    End Sub
#End Region
#End Region

End Class
